package com.yuyue.springFramework.note04.annotation;

import java.lang.annotation.*;

/**
 * 验证注解继承类
 */
public class InheritAnnotation {
    //定义注解1，用在接口上
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Inherited //注解继承
    @interface A1{}

    //定义注解2，用在父类上
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Inherited //注解继承
    @interface A2{}

    //定义接口使用注解1
    @A1
    interface I1{};

    //定义父类使用注解2
    @A2
    class C1{};

    //定义子类继承父类实现接口1
    class C2 extends C1 implements I1{};

    public void fun(){
        //获取子类的所有注解
        for (Annotation annotation:
                C2.class.getAnnotations()) {
            System.out.println(annotation);
        }
    }
}
